#include "dlg_register.h"
#include "ui_dlg_register.h"
#include "supsql.h"
#include<QDebug>
#include<QMessageBox>
dlg_register::dlg_register(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::dlg_register)
{
    ui->setupUi(this);

}

dlg_register::~dlg_register()
{
    delete ui;
}


void dlg_register::on_btnR_Exit_clicked()
{
    exit(0);
}

void dlg_register::on_btnR_ok_clicked()
{
    UserInfo info;
    info.name = ui->EditName->text();
    info.username =ui->EditUser->text().toInt();
    int pwd1 = ui->EditNewPwd->text().toInt();
    int pwd2 = ui->EditNewPwd2->text().toInt();
    auto ptr = supsql::getinstance();
    if(info.name =="" || ui->EditUser->text() == "")
    {
        QMessageBox::warning(nullptr,"错误","姓名或用户名不能为空");
        return;
    }
    if(ui->EditNewPwd->text()==""||ui->EditNewPwd2->text()=="")
    {
        QMessageBox::warning(nullptr,"错误","密码不能为空");
        return;
    }
    if(pwd1 !=pwd2)
    {
        QMessageBox::warning(nullptr,"错误","两次输入密码不一致");
        return;
    }
    info.password =pwd1;
    if(ptr->IsExist(info))
    {
        ptr->UpdatePwd(info);
        QMessageBox::information(nullptr,"正确","修改成功");
        ui->EditName->clear();
        ui->EditNewPwd->clear();
        ui->EditNewPwd->clear();
        ui->EditNewPwd2->clear();
        this->hide();
        return;
    }
    QMessageBox::warning(nullptr,"错误","查无此人");



}

